package com.tgy.JUC.Single;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/***
 * @ClassName: EnumSingle
 * @Description: 枚举类单例模式
 * @Auther: 送你一块二向箔
 * @Date: 14:00 2022/3/16
 * @version : V1.0
 */
public enum EnumSingle {
    INSTANCE;
    private static EnumSingle getInstance(){
        return INSTANCE;
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        EnumSingle instance = EnumSingle.INSTANCE;
        EnumSingle instance2 = EnumSingle.INSTANCE;
        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor(String.class,int.class);
        declaredConstructor.setAccessible(true);
        EnumSingle enumSingle = declaredConstructor.newInstance();

        System.out.println(instance.hashCode());//hashcode 一样
        System.out.println(instance2.hashCode());
        System.out.println(enumSingle.hashCode());//Cannot reflectively create enum objects
    }
}

